<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组件</title>
    <script src="../vue.js"></script>
</head>
<body>

<div id="root">
    <div>
        <input type="text" v-model="inputValue">
        <input type="button" @click="clicked" value="提交">
    </div>
    <ul>
       <todo-item v-for="(item,index) of list" :key="index"
                  :content="item"></todo-item>
    </ul>
</div>


</body>
<script>
    //全局组件
    Vue.component('todo-item',{
        //接收从外部传递进来的属性
        props:['content'],
        template: '<li>{{content}}</li>'
    })


    new Vue({
        el: "#root",
        data: {
            inputValue:"",
            list:[],
        },
        methods:{
            clicked:function () {
                this.list.push(this.inputValue);
                this.inputValue="";
            }
        }
    })

</script>
</html>